﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;

namespace eTerm.Platform.Web
{
    public abstract class BaseUserControl:UserControl
    {

        /// <summary>
        /// 初始化EasyUI控件CSS
        /// </summary>
        protected virtual void InitEasyUI()
        {

        }

        /// <summary>
        /// 初始化用户控件
        /// </summary>
        public virtual void InitControl() { 
            
        }



        /// <summary>
        /// 是否只读控件
        /// </summary>
        public bool IsReadOnly {
            get
            {
                return ViewState["Identity"]==null?false:(bool) ViewState["Identity"];
            }
            set
            {
                ViewState["Identity"] = value;
            }
        }


        /// <summary>
        /// Gets the UID.
        /// </summary>
        /// <value>The UID.</value>
        protected int UID
        {
            get
            {
                return int.Parse(HttpContext.Current.User.Identity.Name);
            }
        }


        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            InitEasyUI();
            if (!IsPostBack)
                InitControl();
        }


        #region RegisterStartupScript
        protected void BaseRegisterStartupScript<T>(T sender, string key, string script, bool addScriptTags)
        {
            if (sender is UpdatePanel)//http://job.cnblogs.com/
                ScriptManager.RegisterStartupScript(sender as UpdatePanel, typeof(T), key, script, addScriptTags);
            else if (sender is Control)
                ScriptManager.RegisterStartupScript(sender as Control, typeof(T), key, script, addScriptTags);
            else if (sender is Page)
                ScriptManager.RegisterStartupScript(sender as Page, typeof(T), key, script, addScriptTags);
        }


        #endregion
    }
}
